
#include <iostream>
#include <stack>
#include <string>

bool isBracket(char c) {
    return (c == '(' || c == ')' || c == '{' || c == '}' || c == '[' || c == ']' || c == '<' || c == '>');
}

bool isValidBracketSequence(const std::string& sequence) {
    std::stack<char> s;
    for (char bracket : sequence) {
        if (isBracket(bracket)) {
            if (bracket == '(' || bracket == '[' || bracket == '{' || bracket == '<') {
                s.push(bracket);
            } else {
                if (s.empty()) {
                    return false;
                }
                char top = s.top();
                if ((bracket == ')' && top != '(') || (bracket == ']' && top != '[') || 
                    (bracket == '}' && top != '{') || (bracket == '>' && top != '<')) {
                    return false;
                }
                s.pop();
            }
        }
    }
    return s.empty();
}

int main() {
    std::string input;
    std::cout << "Введите скобочную последовательность: ";
    std::cin >> input;
    
    if (isValidBracketSequence(input)) {
        std::cout << "True" << std::endl;
    } else {
        std::cout << "False" << std::endl;
    }
    
    return 0;
}